package com.wtwd.device.model;

import com.wtwd.device.constant.SeparatorConstant;
import com.wtwd.device.constant.SetSosConstant;
import com.wtwd.device.util.ByteUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class AppSetSos implements Serializable {
    /**
     * 性别
     */
    private String gender;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 电话号码
     */
    private String telephone;

    /**
     * 0-清空sos联系人 1-未清空联系人 不清空不填
     */
    private Byte clean;

    public AppSetSos() {
    }

    public Byte getClean() {
        return clean;
    }

    public void setClean(Byte clean) {
        this.clean = clean;
    }


    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public static String serialization(List<AppSetSos> list){
        StringBuffer stringBuffer = new StringBuffer();
        for(int i = 0;i < list.size();i++){
            AppSetSos setSos = list.get(i);
            String s = setSos.getTelephone() + SeparatorConstant.POUND_SIGN + ByteUtils.stringToHex(setSos.getNickName()) + SeparatorConstant.POUND_SIGN + setSos.getGender();
            if(setSos.getClean() != null && setSos.getClean().equals(SetSosConstant.TRUE_CLEAN)){
                stringBuffer.append(setSos.getClean());
            }else{
                stringBuffer.append(s);
            }

            if(i + 1 < list.size()){
                stringBuffer.append(SeparatorConstant.CMD_BODY_SEGMENTATION);
            }
        }
        return stringBuffer.toString();
    }


    @Override
    public String toString() {
        return "AppSetSos{" +
                "gender='" + gender + '\'' +
                ", nickName='" + nickName + '\'' +
                ", telephone='" + telephone + '\'' +
                ", clean=" + clean +
                '}';
    }

    public static void main(String[] args) {
        AppSetSos appSetSos1 = new AppSetSos();
        appSetSos1.setTelephone("110");
        appSetSos1.setNickName("我");
        appSetSos1.setGender("1");

        AppSetSos appSetSos2 = new AppSetSos();
        appSetSos2.setTelephone("1100");
        appSetSos2.setNickName("你");
        appSetSos2.setGender("0");

        Byte b = 0;
        AppSetSos appSetSos3 = new AppSetSos();
        appSetSos3.setTelephone("1100");
        appSetSos3.setNickName("你");
        appSetSos3.setGender("0");
        appSetSos3.setClean(b);

        List<AppSetSos> list = new ArrayList<>();
        list.add(appSetSos1);
        list.add(appSetSos2);
        list.add(appSetSos3);
        String serialization = serialization(list);
    }
}
